package org.ucas.faker.web.service.Visualization;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.ucas.faker.web.fetcher.FetchExecutor;
import org.ucas.faker.web.fetcher.FetchReqBuilder;
import org.ucas.faker.web.fetcher.FetchResult;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class SpecialGraphService {
    @Autowired private FetchExecutor fetcher;

    public List<HashMap<String, Object>> getPatentInfo(long depotId) {
        FetchReqBuilder requestBuilder = FetchReqBuilder.instance().depot(depotId).select("id", "ab", "ti", "ap_year");
        System.out.println("SQL: " + requestBuilder.build().sql());
        FetchResult fetchResult = fetcher.fetch(requestBuilder.build());


//        List<HashMap<String, Object>> list = patentMapper.selectPatentGroupByFlowNumber(17);

        List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
        List<String> abstractionList = fetchResult.column("ab");
        List<String> titleList = fetchResult.column("ti");
        List<String> apYearList = fetchResult.column("ap_year");
        List<String> idList = fetchResult.column("id");
//        List<String> primaryClaimList = fetchResult.column("primary_claim");

        for (int i = 0; i < abstractionList.size(); i++) {
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("abstraction", abstractionList.get(i));
            map.put("title", titleList.get(i));
            map.put("primary_claim", "");
            map.put("ap_year", apYearList.get(i));
            map.put("open_year", apYearList.get(i));
            map.put("id", idList.get(i));
            list.add(map);
        }
        return list;
    }
}
